package com.ruoyi.web.controller.safe;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safe.domain.SurroundingEnv;
import com.ruoyi.safe.service.ISurroundingEnvService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 周边环境Controller
 * 
 * @author yxf
 * @date 2021-08-10
 */
@RestController
@RequestMapping("/safe/env")
public class SurroundingEnvController extends BaseController
{
    @Autowired
    private ISurroundingEnvService surroundingEnvService;

    /**
     * 查询周边环境列表
     */
    @PreAuthorize("@ss.hasPermi('safe:env:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurroundingEnv surroundingEnv)
    {
        startPage();
        List<SurroundingEnv> list = surroundingEnvService.selectSurroundingEnvList(surroundingEnv);
        return getDataTable(list);
    }

    /**
     * 导出周边环境列表
     */
    @PreAuthorize("@ss.hasPermi('safe:env:export')")
    @Log(title = "周边环境", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SurroundingEnv surroundingEnv)
    {
        List<SurroundingEnv> list = surroundingEnvService.selectSurroundingEnvList(surroundingEnv);
        ExcelUtil<SurroundingEnv> util = new ExcelUtil<SurroundingEnv>(SurroundingEnv.class);
        return util.exportExcel(list, "周边环境数据");
    }

    /**
     * 获取周边环境详细信息
     */
    @PreAuthorize("@ss.hasPermi('safe:env:query')")
    @GetMapping(value = "/{seId}")
    public AjaxResult getInfo(@PathVariable("seId") Long seId)
    {
        return AjaxResult.success(surroundingEnvService.selectSurroundingEnvById(seId));
    }

    /**
     * 新增周边环境
     */
    @PreAuthorize("@ss.hasPermi('safe:env:add')")
    @Log(title = "周边环境", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurroundingEnv surroundingEnv)
    {
        return toAjax(surroundingEnvService.insertSurroundingEnv(surroundingEnv));
    }

    /**
     * 修改周边环境
     */
    @PreAuthorize("@ss.hasPermi('safe:env:edit')")
    @Log(title = "周边环境", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurroundingEnv surroundingEnv)
    {
        return toAjax(surroundingEnvService.updateSurroundingEnv(surroundingEnv));
    }

    /**
     * 删除周边环境
     */
    @PreAuthorize("@ss.hasPermi('safe:env:remove')")
    @Log(title = "周边环境", businessType = BusinessType.DELETE)
	@DeleteMapping("/{seIds}")
    public AjaxResult remove(@PathVariable Long[] seIds)
    {
        return toAjax(surroundingEnvService.deleteSurroundingEnvByIds(seIds));
    }
}
